<template>
    <div>
        <setHeader title="申请列表"></setHeader>
        <div class="content" style="margin-bottom: 0;">
            <!-- 审核同事、企业申请加入列表 -->
            <div class="business_lists main-application" v-for="(list, index) in CompanyList" :key="index">
                <div class="business_left" style="margin-left: 0.1rem;">
                    <img :src=" list.userhead" v-if="importFileUrl + '/' + list.userhead != null">
                    <img src="../common/images/c_03.jpg" v-else/>
                </div>
                <div class="business_desc" style="width: 3.6rem; margin-left: 0;">
                    <h5>{{list.username}}</h5>
                    <p>{{list.check_info}}</p>
                </div>
                <div class="btn_small_red">
                    <button @click="agreeInfo(list,1)" v-if="list.check == 0">同意</button>
                    <button @click="agreeInfo(list,2)" v-if="list.check == 0">拒绝</button>
                    <button v-if="list.check == 1">已同意</button>
                    <button v-if="list.check == 2" style="background-color: #fff; color: #999; border: 1px solid #999;">已拒绝</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import setHeader from '../public/setHeader.vue';
// import { applyList } from '../api/api';
    export default {
        data() {
            return {
                CompanyList: [],
                isShow: true,
                // cp_id: '',
                importFileUrl: this.$path,
                agereeShow: true,
                refuseShow: true,
                agreebtn: '同意',
                refusebtn: '拒绝',
                applylist: {
                    userId: '',
                    cp_id: '',
                    check_userId: '',
                    reject: ''
                },
                access_token: '',
                userInfo: '',
            }
        },
        components: {
            setHeader
        },
        created() {
            let that = this;
            that.userInfo = JSON.parse(window.localStorage.getItem('userInfo'));
        },
        mounted() {
            // let that = this;
            // var user = Promise.resolve(this.getUserInfo())
            // user.then(
            //     function (result) { 
            //     that.userInfo = result;
            // })
            
            this.applylist.cp_id = this.$route.query.cp_id;
            this.access_token = window.localStorage.getItem('access_token');
        //获取当前企业申请列表
	        this.getUserEnterprise();
        },
        methods: {
            //获取圈子中的企业
            getUserEnterprise() {
                let that = this;
                // let cid = this.cid;
                // this.$fetch(that.$path+'/api.php/Circle/getCircleCompanyList',{cid:cid})
                // .then((res) => {
                //     // console.log('====', res.data);
                //     // that.CompanyList = res.data.list;
                // })
                that.$fetch(that.$path+'/api.php/Company/getNewCompanyColleague',{cp_id:that.applylist.cp_id}).then((res) => {
                    console.log('审核同事', res);
                    if(res.code == 200) {
                        console.log(res.data);
                        that.CompanyList = res.data;
                        res.data.forEach(item => {
                            that.applylist.check_userId = item.user_id;
                            item.reject = that.applylist.reject;
                            console.log('item.check', item.check)
                        });
                    }
                })
            },
            //点击同意与否
            agreeInfo(list,reject){
                let that = this;
                that.applylist.userId = that.userInfo.uid;
                that.applylist.check_userId = list.user_id;
                that.applylist.reject = reject;
                console.log('uid',list.user_id)
                console.log('reject',reject)
                that.$fetch(that.$path+'/api.php/Company/checkUserInCompany', that.applylist).then((res) => {
                    console.log('审核同事22', res);
                    if(res.code == 200) {
                        if(reject == 1) {
                            list.check = 1;
                            // that.CompanyList.check = 1;
                            // that.refuseShow = false;
                            // that.agreebtn = '已同意';
                        }
                        else if(reject == 2) {
                             list.check = 2;
                        }
                    }
                })
            },
        }
    }
</script>

<style>
.main-application:last-child {
    border-bottom: 1px solid #d8d8d8;
}
.main-application .agree_btn {
    background-color: transparent;
    color: #999;
    border: 1px solid #999;
}
</style>